<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            /* background-color: #000;
            width: 108px;
            margin: 0 auto;
            margin-top: 200px;
            height: 40px;
            line-height: 40px;
            color: pink;
            display: flex;
            justify-content:space-around */
            margin: 0 auto;
            margin-top: 200px;
            margin-left: 200px;
            background-color: #fab;
        }
        span{
           
            background-color: #000;
            margin: 0 auto;
            margin-top: 200px;
            height: 40px;
            line-height: 40px;
            color: pink;
        }

    </style>
</head>
<body>
    <div>
        <span class="hour">1</span>
        <span class="minute">2</span>
        <span class="second">3</span>
    </div>
    <script>
        //1.获取元素
        var hour=document.querySelector('.hour');
        var minute=document.querySelector('.minute');
        var second=document.querySelector('.second');
        var inputtime=+new Date('2022-8-5 16:00:00');//返回的是用户输入时间总的毫秒数
        conutDown();//我们先调用函数,防止页面刷新有空白
        //2.开启定时器
        setInterval(conutDown,1000);

        function conutDown(){
            var date1=+new Date();//返回当前时间的毫秒数
           
            var times=(inputtime-date1)/1000;//times剩余时间的秒数
            var d=parseInt(times/60/60/24);
            d=d<10?'0'+d:d;
            var h=parseInt(times/60/60%24); //计算小时
            h=h<10?'0'+h:h;
            hour.innerHTML=h;
            var m=parseInt(times/60%60); //计算分数
            m=m<10?'0'+m:m;
            minute.innerHTML=m;
            var s=parseInt(times%60); //计算当前秒数
            s=s<10?'0'+s:s;
            second.innerHTML=s;
        }

    </script>
</body>
</html>